package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealDishService;
import com.sky.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;


    /**
     * 套餐分页查询
     */
    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("套餐分页查询：{}", setmealPageQueryDTO);
        PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);

        return Result.success(pageResult);
    }

    /**
     * 新增套餐
     */
    @PostMapping
    @ApiOperation("新增套餐")
    Result<String> save(SetmealDTO setmealDTO){
        log.info("新增套餐：{}", setmealDTO);
        setmealService.save(setmealDTO);
        return null;
    }

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    Result<SetmealDTO> getById(@PathVariable Long id){

        SetmealDTO setmealDTO = setmealService.getById(id);

        return Result.success(setmealDTO);
    }

    /**
     * 修改套餐
     * @param id
     * @param setmealDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改套餐")
    Result<String> update(Long id, SetmealDTO setmealDTO){

        setmealService.update(id, setmealDTO);

        return Result.success("修改成功");
    }

    /**
     * 删除套餐
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("批量删除套餐")
    Result<String> delete(long[] ids){

        if (ids == null){
            return Result.success("未选中套餐，请选择");
        }

        setmealService.remove(ids);

        return Result.success("删除成功");
    }

    /**
     * 商品起售、停售
     * @param status
     * @param id
     * @return
     */
    @GetMapping("/status/{status}")
    Result<String> status(Long status, Long id){
        setmealService.status(status, id);

        return Result.success("修改成功");
    }

}
